import datetime
from typing import List, Dict

from sqlalchemy import Boolean, Column, DateTime, Integer, String, Index, ForeignKey, text, and_
from sqlalchemy.orm import Session, relationship

from common.database import Base
from common.database import SessionMixin



class MonitorDorisCustom(Base, SessionMixin):
    __tablename__ = 'monitor_doris_custom'
    service_name = Column(String(128), nullable=False, comment="定制名称")
    log_name = Column(String(128), default="", comment="日志的名称")
    log_level = Column(String(16), default="", comment="日志的级别")
    keywords = Column(String(128), nullable=False, comment="日志的关键字")
    interval = Column(Integer, nullable=False, comment='最近间隔')
    condition = Column(String(16), nullable=False, comment="判断符号")
    threshold = Column(Integer, nullable=False, comment="告警阈值")
    comment = Column(String(255), nullable=True, comment="定制说明")
    create_time = Column(DateTime, default=datetime.datetime.now, nullable=False, comment="创建时间")
    update_time = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, nullable=False, comment="更新时间")

    __table_args__ = (
        Index('idx_monitor_doris_service_uuid', 'uuid', unique=True),
        {
            'mysql_engine': 'innodb',
            'mysql_charset': 'utf8mb4',
            'mysql_collate': 'utf8mb4_unicode_ci',
            'extend_existing': True,
            'mysql_row_format': 'dynamic',
        }
    )

    def __repr__(self):
        return "<uuid='{}',service_name='{}'>".format(self.uuid, self.service_name)

    @classmethod
    def get_all_custom(cls, db: Session):
        return db.query(cls).to_dict()


    